package protocol

import (
	"context"
	"net/http"

	"gitee.com/LangHuaHuachihua/blog-go/conf"
	"gitee.com/LangHuaHuachihua/blog-go/logger"
	"github.com/gin-gonic/gin"
)

// 具体路由器框架，传入,其他的也可以切换
func NewHttp(r *gin.Engine) *Http {

	return &Http{server: &http.Server{
		Addr:    conf.C().HttpConfig.String(),
		Handler: r, //指定httpserver的路由用gin(可以切其他框架)
	}}
}

type Http struct {
	server *http.Server
}

func (h *Http) Start() error {
	logger.L().Debug().Msgf("Http server %s", h.server.Addr)
	return h.server.ListenAndServe()
}

func (h *Http) Stop(ctx context.Context) {
	h.server.Shutdown(ctx)
}
